<?php

class Core_Backend_Component_Article_View_Category_Create extends Core_Backend_Share_View_Form {
	
    protected function buildToolbar($toolbar) {
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('article/category/index'), $this->__('share.button.back'));
        if($this->getIdentity()->isAllowAction('article_category_edit')){
	        $group = $toolbar->createGroup('save');
	        $group->addButton($this->__('share.button.save'))
	        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('" . $this->getUrl(NULL, 'save') . "')");
        }
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setId('cateogry_form')
             ->addHiddenField('id', 'category[id]')
             ->addHiddenField('area_id', 'category[area_id]', $this->getArea());
        $form->addTextboxField($this->__('share.label.title'), 'title', 'category[title]', TRUE)->addRequiredRule();
        $form->addTextboxField($this->__('share.label.sef_url'), 'sef_url', 'category[sef_url]');
        $form->addSelectField($this->__('share.label.theme'), 'theme_id', 'category[theme_id]')
                ->bindData($this->getThemes(), 'title', 'id');
//        $form->addComboTreeField($this->__('share.label.menu'), 'menu_id', "category[menu_id]", TRUE)
//                ->bindData($this->getMenus()->toArray(), 0, array('valueKey'=>'id', 'textKey'=>'name', 'parentKey'=>'parent_id', 'childKey'=>'id'));
        
        $categories = $this->getParentCategories()->toArray();
        
        $form->addComboTreeField($this->__('article.label.parent_category'), 'parent_id', "category[parent_id]")
                ->bindData($categories, 0, array('valueKey'=>'id', 'textKey'=>'title', 'parentKey'=>'parent_id', 'childKey'=>'id'))
                ->setDefaultOption('0', '--');
//        $form->addSelectField($this->__('share.label.template'), 'template_id', 'category[template_id]', TRUE)
//                ->bindData($this->getTemplates(), 'name', 'id')
//                ->addRequiredRule();
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }

}